package cn.wolfcode.rbac.service.impl;

import cn.wolfcode.rbac.domain.Department;
import cn.wolfcode.rbac.mapper.DepartmentMapper;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.IDepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper mapper;
    public void saveOrUpdate(Department u) {
        if(u.getId()==null){
            mapper.insert(u);
        }else{
            mapper.updateByPrimaryKey(u);
        }
    }


    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
        mapper.updateEmployeeAfterDelete(id);
    }


    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Department> result = mapper.queryForList(qo);
        return new PageInfo(result);
    }


    public Department selectOne(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<Department> listAll() {
        return mapper.selectAll();
    }


}
